﻿using System;
using System.Collections.Specialized;

namespace UMC.Net
{
    public delegate void NetWriteData(byte[] buffer, int offset, int size);

    public delegate int NetReadData(byte[] buffer, int offset, int size);
    public abstract class NetContext
    {

        public abstract NetLoger Loger { get; }
        public abstract int StatusCode
        {
            get;
            set;
        }
        public abstract StringValue ContentType
        {
            get;
            set;
        }
        public abstract long? ContentLength
        {
            get;
            set;
        }
        public abstract string UserHostAddress
        {
            get;
        }

        public abstract StringValue Host { get; }

        // public abstract string RemoteIPAddress
        // {
        //     get;
        // }
        public abstract StringValue Path
        {
            get;
        }
        public abstract StringValue PathQuery
        {
            get;
        }
        public abstract StringValue Scheme { get; }
        public abstract StringValue Query
        {
            get;
        }
        public abstract bool IsWebSocket
        {
            get;
        }
        public abstract StringValue UserAgent
        {
            get;
        }
        public abstract void AddHeader(HeadValue head);
        public abstract void AddHeader(string name, string value);

        public void AddHeader(StringValue name, StringValue value)
        {
            this.AddHeader(new HeadValue(name, value));
        }
        public abstract void AddHeader(StringValue name, String value);
        public abstract void AppendCookie(string name, string value);
        public abstract void AppendCookie(string name, string value, string path);
        public abstract HeadValues Headers
        {
            get;
        }

        /// <summary>
        /// 退出
        /// </summary>
        public virtual void SignOut()
        {
            this.Token?.SignOut()?.Commit(this.UserHostAddress, this.Server);
        }
        public abstract HeadValues Cookies
        {
            get;
        }
        public virtual UMC.Security.AccessToken Token
        {
            get;
            set;
        }
        public abstract void OutputHeaded(Action action);
        public abstract ByteChunk Memory
        {
            get;
        }
        public abstract void ReadAsForm(Action<HeadValues> action);
        public abstract void ReadAsData(Net.NetWriteData readData);


        public virtual void UseSynchronousIO()
        {

        }
        public virtual void OutputFinish()
        {

        }
        public virtual void Error(Exception ex)
        {

        }
        public abstract TextWriter Output
        {
            get;
        }

        public abstract System.IO.Stream OutputStream
        {
            get;
        }
        public abstract HttpMethod Method
        {
            get;
        }


        public abstract void Redirect(StringValue url);
        public abstract void Redirect(string url);

        public Object Tag
        {
            get; set;
        }
        public abstract string Server
        {
            get;
        }
        public abstract StringValue RawUrl
        {
            get;
        }


        public abstract HeadValues QueryString
        {
            get;
        }
        public abstract void RewriteUrl(String pathAndQuery);
        public abstract Uri UrlReferrer
        {
            get;
        }
        public abstract Uri Url
        {
            get;
        }
        public Guid? AppKey
        {
            get; set;
        }

        public virtual void NotCounted()
        {

        }

    }


}
